/**
 * @author phoenics@126com
 * @date 2017年11月7日 下午2:21:35
 * @version V1.0
 */

package com.jx.gocom.nlp;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.sqlite.SQLiteDataSource;

/**
 *
 */
@Configuration
public class EmbeddedDataSourceConfiguration {
	private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(EmbeddedDataSourceConfiguration.class);
	
	@Value("${gocom.nlp.classify.bayes}")
	String classifydb = "bayes.db3";
	@Bean(destroyMethod = "", name = "EmbeddeddataSource")
    public DataSource dataSource() {
        DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
        dataSourceBuilder.driverClassName("org.sqlite.JDBC");
        dataSourceBuilder.url("jdbc:sqlite:" + this.classifydb);
        dataSourceBuilder.type(SQLiteDataSource.class);
        return dataSourceBuilder.build();
    }
	
	@Bean()
    public JdbcTemplate primaryJdbcTemplate(
            @Qualifier("EmbeddeddataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
	
}
